<template>
	<view class='contents'>
		<!-- <view class="top-back" @click="goback()">
			<uni-icons type="arrow-left" color="#000" size="40rpx"></uni-icons>
		</view> -->
		<view class="h1">密码登录</view>
		<view class="form">
			<view class="form-item">
				<view class="label">手机号</view>
				<view class="ipt-box">
					<input type="text" v-model="mobile" class="ipt" placeholder="请输入手机号" />
				</view>
			</view>
			<view class="form-item">
				<view class="label">密码</view>
				<view class="ipt-box">
					<input type="password" v-model="password" class="ipt" placeholder="请输入密码" />
				</view>
			</view>
		</view>
		<!-- <view class="sign-box flex flex-between">
			<view class="a-btn" @click="goto('user/reg')">注册</view>
			<view class="a-btn" @click="goto('user/forget')">忘记密码？</view>
		</view> -->
		<view class="btn" @click="doLogin()">确定</view>
		<!-- <view class="agreement flex">
			<uni-icons :type="agree ? 'circle-filled' : 'circle'" :color="agree ? baseColor : '#D9D9D9'" size="40rpx"
				@click="agree = !agree"></uni-icons>
			<view class="agreeCon" @click="agree = !agree">
				我已经阅读并同意<text class="agree-a" @click.stop="goto('public/agree')">《知情必报协议》</text><text class="agree-a"
					@click.stop="goto('public/agree?type=privacy')">《个人信息保护指引》</text>
			</view>
		</view> -->
	</view>
</template>

<script setup lang="ts">
import { ref } from "vue"
import { onLoad } from "@dcloudio/uni-app"
import { goto, goback, tip, confirm } from "@/utils/utils"
import { login } from "../../api/public";
/*************/
const mobile = ref("")
const password = ref("")
const agree = ref(false)
onLoad(() => {

})
const doLogin = () => {
	if (!mobile.value) {
		return tip('请输入手机号！')
	}
	if (!password.value) {
		return tip('请输入密码！')
	}
	/* if (!agree.value) {
		confirm("是否已阅读并同意协议？", () => {
			agree.value = true
			
		})
	}
	else {
		done()
	} */
	done()
}
const done = () => {
	let data = {
		"form":{
			"username": mobile.value,
			"password": password.value
		}
	}
	login(data).then((res: any) => {
		if (res.error == 0) {		//登录成功
			let token = res.data.token
			uni.setStorageSync('token', token)
			uni.setStorageSync('user', res.data.info)
			//goto('user/user', '', 0, true)
			goback()
		}
		else {
			tip(res.msg)
		}
	})
}
</script>

<style lang='scss' scoped>
.contents {
	background-color: #f9f9f9;
	padding: 70rpx 50rpx 40rpx;
	min-height: 100vh;

	.h1 {
		margin-top: 50rpx;
		font-size: 60rpx;
		font-weight: 600;
	}

	.form {
		margin-top: 104rpx;

		.form-item {
			margin-bottom: 30rpx;

			.label {
				font-weight: bold;
				font-size: 28rpx;
				color: rgba(0, 0, 0, 0.85);
				line-height: 28rpx;
			}

			.ipt-box {
				margin-top: 24rpx;
				background-color: #ffffff;
				height: 100rpx;
				line-height: 100rpx;
				border-radius: 20rpx;
				padding: 0 32rpx;

				.ipt {
					width: 100%;
					height: 100%;
				}
			}
		}
	}

	.sign-box {
		font-size: 28rpx;
		color: #666;
	}

	.btn {
		margin-top: 62rpx;
	}

	.agreement {
		margin-top: 48rpx;
		font-size: 24rpx;

		.agreeCon {
			margin-left: 10rpx;
			line-height: 40rpx;

			.agree-a {
				color: $baseColor;
			}
		}
	}
}
</style>
